Returns a random number between 0 and 1.
0 から 1 の間の乱数を返します。
Rnd [(Expression)]
Rnd [(Expression)]
Double
倍精度
Expression: Any numeric expression that defines how to generate random numbers.
Expression: 乱数の発生の種とする任意の数値表式。
Less than zero: Always returns the same random number.
ゼロより小さい数値: 常に同じ乱数系列を生成して返します。
Greater than zero: Returns the next random number in the sequence.
ゼロより大きい数値: 乱数系列の次の値を生成して返します。
Zero: Returns the random number that was last generated.
ゼロ: 前回と同じ乱数系列を生成して返します。
Omitted: Returns the next random number in the sequence.
省略時: 乱数系列の次の値を生成して返します。
If the same number is passed for each successive call to the Rnd function, the same random-number sequence is generated. This is because the Expression parameter is used as a starting point for the next number.
Rnd 関数を呼び出す際に常に同じ値を渡すと、同じ乱数系列が生成されます。これは Expression に指定するパラメータが、次の数値を生成する際に利用されるからです。
The Rnd function only returns values ranging from 0 to 1. To generate random integers in a given range, use the formula in the following example:
Rnd 関数で生成できるのは 0 から 1 までの数値であり、これ以外の範囲の整数値を取る乱数が必要であれば、下記の例を参考にしてください。
Sub ExampleRandomSelect
Sub ExampleRandomSelect
Dim iVar As Integer
Dim iVar As Integer
iVar = Int((15 * Rnd) -2)
IVar = Int((15 * Rnd) -2)
Select Case iVar
Select Case iVar
Case 1 To 5
Case 1 To 5
Print "Number from 1 to 5"
Print "Number from 1 to 5"
Case 6, 7, 8
Case 6, 7, 8
Print "Number from 6 to 8"
Print "Number from 6 to 8"
Case Is > 8 And iVar < 11
Case Is > 8 And iVar < 11
Print "Greater than 8"
Print "Greater than 8"
Case Else
Case Else
Print "Outside range 1 to 10"
Print "Outside range 1 to 10"
End Select
End Select
end sub
end sub